package com.ts.base.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.esapp.service.base.BaseInfoServere;
import com.ts.base.bean.User;
import com.ts.common.bean.DataType;
import com.ts.common.bean.DataTypeReport;
import com.ts.common.bean.ResponResult;


@Controller
@RequestMapping("/base")
public class BaseController {
	
	private final Logger logger = LoggerFactory.getLogger(BaseController.class);
	
	@Autowired
	private BaseInfoServere baseInfoServere;
	
	
	@RequestMapping("/dataType")
	@ResponseBody
	public List<DataType> show() {
		return DataTypeReport.DATA_TYPES;
	}
	
	@RequestMapping("/login")
	public String login(HttpServletRequest request ,User user) {
		logger.info("用户登录。。。。");
		User u = baseInfoServere.checkUserInfo( user );
		
		if( u == null ) {
			request.setAttribute("message", "未找到用户");
			logger.error("未找到"+user.getuName()+"的用户");
			return "index";
		}
		
		HttpSession session = request.getSession();
		if ( session.isNew() ) {
			session.setAttribute("userinfo", u);
		}
		return "../index";
	}
	
	@RequestMapping("/createGroup")
	public ResponResult createGroup() {
		
		return ResponResult.success();
	}
	

}
